/**
 *  This file is part of PennerBot
 *
 *  Copyright (C) 2010 microkernel
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <core/strings.hpp>

namespace PBot
{
namespace Core
{

const char MULTI_LOGIN_USERNAME_RX[] = "<input type=\"text\" class=\"text\" name=\"(.*?)\" id=\"login_username\" maxlength=\".*?\"";
const char MULTI_LOGIN_PASSWORD_RX[] = "<input.*?type=\"password\" name=\"(.*?)\" id=\"password\" class=\".*?\" />";
const char MULTI_LOGIN_CITY_RX[] = "<option id=\"\\w*?\"\\s*?value=\"(\\S*?)\"\\s*?onclick=\"\\V*?\"\\s*?selected=\"selected\">";

const char MULTI_LOGIN_WRONGPASS[] = "<div class='errmsg'>";
const char MULTI_LOGIN_PASSED[] = "icon money";

const char MULTI_BC_CAPTCHAURL_RX[] = "document.getElementById\\(\"captcha_img\"\\).src=\"(.*?)\"";
const char MULTI_BC_COUNTER_RX[] = "<a\\s*?href=\"/activities/\"\\V*?title=\"\\V*?\"\\V*?>\\s*?<script\\V*?type=\"text/javascript\">counter\\((.*?)\\)</script>";
const char MULTI_BC_FIGHTCOUNTER_RX[] = "<a\\s*?href=\"/fight/\"\\V*?title=\"\\V*?\"\\V*?>\\s*?<script\\V*?type=\"text/javascript\">counter\\((.*?)\\)</script>";
const char MULTI_BC_CRIMECOUNTER_RX[] = "<div id=\"active_process2\".*?counter\\((.*?)\\)";
const char MULTI_BC_FORMCHECK_RX[] = ".*?<form\\V*?>\\s*?<input\\V*?name=\"sammeln\"\\V*?>\\s*?<input\\V*?name=\"konzentrieren\"\\V*?>\\s*?<input\\V*?name=\"captchacheck\"\\V*?>\\s*?<input\\V*?>\\s*</form>.*?";
const char MULTI_BC_CONC_RX[] = ".*?<option\\s*?value=\"60\"\\s*?selected>\\V*?</option>.*?";
const char MULTI_BC_FORMCONC_RX[] = "<input\\V*?name=\"konzentrieren\"\\V*?value=\"(\\V*?)\"\\V*>";
const char MULTI_BC_FORMACTION_RX[] = "<input\\V*?type=\"button\"\\V*?name=\"Submit2\"\\V*?onclick=\"javascript:setupForm\\('(\\V*?)'\\)";
const char MULTI_BC_OLDJUNK_RX[] = "<h3>\\V*?</h3>\\s*?<h4><img src=\"(\\V*?)\"\\V*?>\\V*?</h4>";
const char MULTI_BC_JUNKENGINE_RX[] = "<img\\V*?src=\"\\V*?/plunder/mofamotor\\.png\"\\V*?>\\s*?</td>\\s*?<td\\V*?class=\"col2\"\\V*?>\\s*?<a\\V*?href=\"javascript\\:change_stuff\\('(\\d*?)'\\)\"\\V*?>";
const char MULTI_BC_JUNKFORMACTION_RX[] = "<form\\V*?name=\"form_skip\"\\V*?action=\"(\\V*?)\">";
const char MULTI_BC_JUNKFORMID_RX[] = "<form\\V*?name=\"form_skip\"\\V*?action=\"\\V*?\">\\s*?<input\\V*?name=\"(\\V*?)\"\\V*?>\\s*?</form>";

const char MULTI_BC_CART_TYPE_RX[] = "<input\\V*?type=\"hidden\"\\V*?name=\"type\"\\V*?value=\"(\\V*?)\">";
const char MULTI_BC_CART_PENDING_RX[] = "<input\\V*?type=\"hidden\"\\V*?name=\"bottlecollect_pending\"\\V*?value=\"(\\V*?)\">";
const char MULTI_BC_CART_SUBMIT_RX[] = "<input\\V*?type=\"submit\"\\V*?class=\"button_skill\"\\V*?name=\"Submit2\"\\V*?value=\"(\\V*?)\">";
const char MULTI_BC_CART_ACTION_RX[] = "<form\\V*?name=\"\\V*?\"\\V*?action=\"(\\V*?)\"\\V*?method=\"post\">";

const char MULTI_BC_JUNKID_FRONT[] = "<img\\V*?src=\"\\V*?";
const char MULTI_BC_JUNKID_BACK[] = "\"\\V*?></td>\\s*?<td\\V*?class=\"col2\">\\s*?<a\\V*?href=\"javascript:change_stuff\\('(\\d*?)'\\)\">";
const char MULTI_BC_JUNKENGINE[] = "/plunder/mofamotor\\.png";
const char MULTI_BC_SHOPPINGCART[] = "bottlecollect_pending";

const char MULTI_BS_CONTAINER_RX[] = "<ul\\V*?class=\"first\">\\s*?<li>\\s*?\\V*?([0-9,\\.]*?)\\s*?\\V*?\\s*?<div\\V*?class=\"processbar_bg\"";
const char MULTI_BS_MONEY_RX[] = "<a\\s*?href=\"/financial/\"\\V*?>\\s*\\V*?([0-9,\\.]*?)\\s*?</a>";
const char MULTI_BS_EXCHANGERATE_RX[] = "<font\\s*?id=\"wirkung\">\\s*?\\V*?\\s*?\\V*?([0-9,\\.]*?)\\s*?</font>";
const char MULTI_BS_BOTTLECOUNT_RX[] = "width=\"250\">[\\s]*<span>[\\s]*([0-9]*) ";
const char MULTI_BS_ACTION_RX[] = "<div\\s*?class=\"listshop\">\\s*?<form\\V*?method=\"post\"\\V*?action=\"(\\V*?)\">";
const char MULTI_BS_CHKVAL_RX[] = "<input\\s*?id=\"chkval\"\\V*?name=\"chkval\"\\V*?value=\"(\\V*?)\"\\V*?/>";

const char MULTI_BS_MAX[] = "<input id=\"max\" type=\"hidden\" name=\"max\"";
const char MULTI_BS_SUM[] = "<input id=\"menge_verkauf\" type=\"text\" size=\"3\" name=\"sum\"";
const char MULTI_BS_BUTTON[] = "<input type=\"button\" value=\"max.\"";

#ifdef PBOT_SPECIAL

const char MULTI_AS_SKILLCOUNTER_RX[] = "<a\\s*?href=\"/skills/\"\\V*?title=\"\\V*?\"\\V*?>\\s*?<script\\V*?type=\"text/javascript\">counter\\((.*?)\\)</script>";

const char MULTI_AS_ATT[] = "att";
const char MULTI_AS_DEF[] = "def";
const char MULTI_AS_DEX[] = "agi";
const char MULTI_AS_SPEECH[] = "sprechen";
const char MULTI_AS_EDU[] = "bildungsstufe";
const char MULTI_AS_MUSIC[] = "musik";
const char MULTI_AS_SOCIAL[] = "sozkontakte";
const char MULTI_AS_CONCENTRATION[] = "konzentration";
const char MULTI_AS_PICKPOCKET[] = "pickpocket";

#endif /* PBOT_SPECIAL */

Strings* Strings::instance = NULL;

Strings::Strings()
{
    std::map<Regexes, Regex*> DE_RX;
    DE_RX[LOGIN_USERNAME] = new Regex(MULTI_LOGIN_USERNAME_RX);
    DE_RX[LOGIN_PASSWORD] = new Regex(MULTI_LOGIN_PASSWORD_RX);
    DE_RX[LOGIN_CITY] = new Regex(MULTI_LOGIN_CITY_RX);
    DE_RX[BC_CAPTCHAURL] = new Regex(MULTI_BC_CAPTCHAURL_RX);
    DE_RX[BC_COUNTER] = new Regex(MULTI_BC_COUNTER_RX);
    DE_RX[BC_FIGHTCOUNTER] = new Regex(MULTI_BC_FIGHTCOUNTER_RX);
    DE_RX[BC_CRIMECOUNTER] = new Regex(MULTI_BC_CRIMECOUNTER_RX);
    DE_RX[BC_FORMCHECK] = new Regex(MULTI_BC_FORMCHECK_RX);
    DE_RX[BC_CONCENTRATION] = new Regex(MULTI_BC_CONC_RX);
    DE_RX[BC_FORMCONC] = new Regex(MULTI_BC_FORMCONC_RX);
    DE_RX[BC_FORMACTION] = new Regex(MULTI_BC_FORMACTION_RX);
    DE_RX[BC_OLDJUNK] = new Regex(MULTI_BC_OLDJUNK_RX);
    DE_RX[BC_JUNKENGINE_RX] = new Regex(MULTI_BC_JUNKENGINE_RX);
    DE_RX[BC_JUNKFORMACTION] = new Regex(MULTI_BC_JUNKFORMACTION_RX);
    DE_RX[BC_JUNKFORMID] = new Regex(MULTI_BC_JUNKFORMID_RX);
    DE_RX[BC_CART_TYPE] = new Regex(MULTI_BC_CART_TYPE_RX);
    DE_RX[BC_CART_PENDING] = new Regex(MULTI_BC_CART_PENDING_RX);
    DE_RX[BC_CART_SUBMIT] = new Regex(MULTI_BC_CART_SUBMIT_RX);
    DE_RX[BC_CART_ACTION] = new Regex(MULTI_BC_CART_ACTION_RX);
    DE_RX[BS_CONTAINER] = new Regex(MULTI_BS_CONTAINER_RX);
    DE_RX[BS_MONEY] = new Regex(MULTI_BS_MONEY_RX);
    DE_RX[BS_EXCHANGERATE] = new Regex(MULTI_BS_EXCHANGERATE_RX);
    DE_RX[BS_BOTTLECOUNT] = new Regex(MULTI_BS_BOTTLECOUNT_RX);
    DE_RX[BS_ACTION] = new Regex(MULTI_BS_ACTION_RX);
    DE_RX[BS_CHKVAL] = new Regex(MULTI_BS_CHKVAL_RX);

#ifdef PBOT_SPECIAL

    DE_RX[AS_SKILLCOUNTER] = new Regex(MULTI_AS_SKILLCOUNTER_RX);

#endif /* PBOT_SPECIAL */


    regexes.push_back(DE_RX); // Hamburg
    regexes.push_back(DE_RX); // Berlin
    regexes.push_back(DE_RX); // Munich
    regexes.push_back(DE_RX); // Dossergame
    regexes.push_back(DE_RX); // Warschau
    regexes.push_back(DE_RX); // Krakau
    regexes.push_back(DE_RX); // Frankreich Paris
    regexes.push_back(DE_RX); // Frankreich Marseille
    regexes.push_back(DE_RX); // Spanien
    regexes.push_back(DE_RX); // Tuerkei
    regexes.push_back(DE_RX); // USA
    regexes.push_back(DE_RX); // Brasilien
    regexes.push_back(DE_RX); // Malle
    regexes.push_back(DE_RX); // Koeln

    std::map<String, const char*> DE_STR;
    DE_STR[LOGIN_WRONGPASS] = MULTI_LOGIN_WRONGPASS;
    DE_STR[LOGIN_PASSED] = MULTI_LOGIN_PASSED;
    DE_STR[BC_JUNKID_FRONT] = MULTI_BC_JUNKID_FRONT;
    DE_STR[BC_JUNKID_BACK] = MULTI_BC_JUNKID_BACK;
    DE_STR[BC_JUNKENGINE] = MULTI_BC_JUNKENGINE;
    DE_STR[BC_SHOPPINGCART] = MULTI_BC_SHOPPINGCART;
    DE_STR[BS_MAX] = MULTI_BS_MAX;
    DE_STR[BS_SUM] = MULTI_BS_SUM;
    DE_STR[BS_BUTTON] = MULTI_BS_BUTTON;

#ifdef PBOT_SPECIAL

    DE_STR[AS_ATT] = MULTI_AS_ATT;
    DE_STR[AS_DEF] = MULTI_AS_DEF;
    DE_STR[AS_DEX] = MULTI_AS_DEX;
    DE_STR[AS_EDU] = MULTI_AS_EDU;
    DE_STR[AS_MUSIC] = MULTI_AS_MUSIC;
    DE_STR[AS_SOCIAL] = MULTI_AS_SOCIAL;
    DE_STR[AS_CONCENTRATION] = MULTI_AS_CONCENTRATION;
    DE_STR[AS_PICKPOCKET] = MULTI_AS_PICKPOCKET;

#endif /* PBOT_SPECIAL */

    strings.push_back(DE_STR); // Hamburg
    strings.push_back(DE_STR); // Berlin
    strings.push_back(DE_STR); // Munich
    strings.push_back(DE_STR); // Dossergame
    strings.push_back(DE_STR); // Warschau
    strings.push_back(DE_STR); // Krakau
    strings.push_back(DE_STR); // Frankreich Paris
    strings.push_back(DE_STR); // Frankreich Marseille
    strings.push_back(DE_STR); // Spanien
    strings.push_back(DE_STR); // Tuerkei
    strings.push_back(DE_STR); // USA
    strings.push_back(DE_STR); // Brasilien
    strings.push_back(DE_STR); // Malle
    strings.push_back(DE_STR); // Koeln

}

Strings::~Strings()
{
    for(std::map<Regexes, Regex*>::iterator ito = regexes[0].begin(); ito != regexes[0].end(); ++ito)
    {
        delete ito->second;
    }
}

Strings& Strings::GetInstance()
{
    if(!instance)
    {
        instance = new Strings();
    }

    return *instance;
}

void Strings::Destroy()
{
    delete instance;
    instance = NULL;
}

const char* Strings::GetString(Config::Games game, String string)
{
    boost::recursive_mutex::scoped_lock lock(mutex);
    return strings[game][string];
}

Regex* Strings::GetRegex(Config::Games game, Regexes regex)
{
    boost::recursive_mutex::scoped_lock lock(mutex);
    return regexes[game][regex];
}



}
}
